﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WebApplication3.Models;

namespace Api.Catalog.Controllers
{
    [Route("api/[controller]/[action]")]
    public class TokenController: ControllerBase
    {
        private ITokenHelper tokenHelper = null;
        public TokenController(ITokenHelper _tokenHelper)
        {
            tokenHelper = _tokenHelper;
        }


        [HttpGet]
        [AllowAnonymous]
        public IActionResult Login(string code, string pwd)
        {
            User user = TemporaryData.GetUser(code);
            if (null != user && user.Password.Equals(pwd))
            {
                return Ok(tokenHelper.NewCreateToken(user));
            }
            return BadRequest();
        }
    }
}
